//计算节点数量
export const countTreeNodes = (tree: any) => {
	let count = 0
	const stack = [...tree] // 使用栈来保存需要处理的节点

	while (stack.length > 0) {
		const node = stack.pop() // 从栈中取出最后一个节点
		if (!node.children || node.children.length === 0) {
			count++ // 当前节点是叶子节点，计数
		} else {
			// 将子节点添加到栈中进行处理
			stack.push(...node.children)
		}
	}

	return count
}

//选中节点
export const selectTreeNodes = (tree: any) => {
	let treeLeafs: any[] = []
	let stack: any[] = [...tree]

	while (stack.length > 0) {
		const node = stack.pop()
		if (node) {
			treeLeafs.push(node.key)
			if (node.children && node.children.length > 0) {
				stack.push(...node.children)
			}
		}
	}

	return treeLeafs
}

// 搜索节点
export const searchTreeNodes = (tree: any, targetValue: any) => {
	console.log(tree)
	console.log(targetValue)
}
